home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / htalert.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  5.2 KB  |  215 lines

  1. #define Uses_MsgBox
  2. #define Uses_TProgram
  3. #define Uses_TButton
  4. #define Uses_TDialog
  5. #define Uses_TInputLine
  6. #define Uses_TLabel
  7. #define Uses_TDeskTop
  8. #include"tcapture.h"
  9. #include"tpasswor.h"
  10.  
  11. //    C callable rourtines using CPP.
  12. extern "C"    {
  13.  
  14. #include"capalloc.h"
  15. #include"capstdio.h"
  16. #include "HTAlert.h"
  17.  
  18. #include "tcp.h"
  19. #include <ctype.h>
  20.  
  21. PUBLIC void HTAlert ARGS1(CONST char *, Msg)
  22. {
  23.     fprintf(stderr, "WWW Alert:  %s\n", Msg);
  24. }
  25.  
  26.  
  27. PUBLIC void HTProgress ARGS1(CONST char *, Msg)
  28. {
  29.     fprintf(stderr, "WWW:  %s ...\n", Msg);
  30. }
  31.  
  32.  
  33. PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
  34. {
  35.     auto unsigned short int usi_msg = messageBox(Msg, mfYesButton |
  36.         mfNoButton | mfConfirmation);
  37.  
  38.     if(cmYes == usi_msg)    {
  39.         return(YES);
  40.     }
  41.     else    {
  42.         return(NO);
  43.     }
  44. }
  45.  
  46.  
  47. PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
  48. {
  49.     //    General use rectangle.
  50.     auto TRect TR(0, 0, 50, 7);
  51.  
  52.     //    Create a dialog that asks for some WWW info.
  53.     TDialog *TDp_WWW = new TDialog(TR, Msg);
  54.     if(TDp_WWW == NULL)    {
  55.         doslynxmessage("Unable to create WWW dialog.");
  56.         auto char *cp_default = NULL;
  57.         StrAllocCopy(cp_default, deflt);
  58.         return(cp_default);
  59.     }
  60.  
  61.     //    Set some dialog options.
  62.     TDp_WWW->options |= ofCentered;
  63.  
  64.     //      Make the input line to enter the information.
  65.     TR = TRect(6, 2, 44, 3);
  66.     TInputLine *TILp_inputLine = new TInputLine(TR, usi_TILURLSize - 1);
  67.     //    Put in the default response
  68.     if(deflt != NULL && *deflt != '\0')    {
  69.         TILp_inputLine->setData((void *)deflt);
  70.     }
  71.     TDp_WWW->insert(TILp_inputLine);
  72.  
  73.  
  74.     //    Make the input line's label.
  75.     auto char ca_buffer[usi_TILURLSize];
  76.     TR = TRect(5, 1, 25, 2);
  77.     sprintf(ca_buffer, "~W~WW %s", Msg);
  78.     TLabel *TLp_prompt = new TLabel(TR, ca_buffer, TILp_inputLine);
  79.     TDp_WWW->insert(TLp_prompt);
  80.  
  81.     //    Insert the Ok button.  The user has to enter something....
  82.     auto TButton *TBp_button;
  83.     TR = TRect(19, 4, 31, 6);
  84.     TBp_button = new TButton(TR, "~O~K", cmOK, bfDefault);
  85.     TDp_WWW->insert(TBp_button);
  86.  
  87.     //    Stay in the input line.
  88.     TDp_WWW->selectNext(False);
  89.  
  90.     //    Draw the dialog.
  91.     TDp_WWW->drawView();
  92.  
  93.     //    Execute the dialog.
  94.     TProgram::deskTop->execView(TDp_WWW);
  95.  
  96.     //    User can't cancel, save what we got as the proper input,
  97.     //    or use the default.
  98.     TILp_inputLine->getData(ca_buffer);
  99.  
  100.     //    Take out whitespaces....
  101.     auto char *cp_nowhite;
  102.     while(isspace(ca_buffer[0]))    {
  103.         cp_nowhite = ca_buffer + 1;
  104.         do    {
  105.             *(cp_nowhite - 1) = *cp_nowhite;
  106.         }
  107.         while(*cp_nowhite);
  108.     }
  109.  
  110.     //    If no string, use the default.
  111.     if(strlen(ca_buffer) == 0)    {
  112.         strcpy(ca_buffer, deflt);
  113.     }
  114.  
  115.     //    Done with dialog.
  116.     TObject::destroy(TDp_WWW);
  117.  
  118.     //    Return input.
  119.     auto char *cp_returnval = NULL;
  120.     StrAllocCopy(cp_returnval, ca_buffer);
  121.     return(cp_returnval);
  122. }
  123.  
  124.  
  125. PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
  126. {
  127.     //    General use rectangle.
  128.     auto TRect TR(0, 0, 50, 7);
  129.  
  130.     //    Create a dialog that asks for some WWW info.
  131.     TDialog *TDp_password = new TDialog(TR, "Password");
  132.     if(TDp_password == NULL)    {
  133.         doslynxmessage("Unable to create password dialog.");
  134.         auto char *cp_default = NULL;
  135.         StrAllocCopy(cp_default, "");
  136.         return(cp_default);
  137.     }
  138.  
  139.     //    Set some dialog options.
  140.     TDp_password->options |= ofCentered;
  141.  
  142.     //      Make the input line to enter the information.
  143.     TR = TRect(6, 2, 44, 3);
  144.     TPasswordInputLine *TPILp_passwordLine = new TPasswordInputLine(TR,
  145.         usi_TILURLSize - 1);
  146.     TDp_password->insert(TPILp_passwordLine);
  147.  
  148.  
  149.     //    Make the input line's label.
  150.     auto char ca_buffer[usi_TILURLSize];
  151.     sprintf(ca_buffer, "~W~WW %s", Msg);
  152.     TR = TRect(5, 1, 25, 2);
  153.     TLabel *TLp_prompt = new TLabel(TR, ca_buffer, TPILp_passwordLine);
  154.     TDp_password->insert(TLp_prompt);
  155.  
  156.     //    Insert the Ok button.  The user has to enter something....
  157.     auto TButton *TBp_button;
  158.     TR = TRect(19, 4, 31, 6);
  159.     TBp_button = new TButton(TR, "~O~K", cmOK, bfDefault);
  160.     TDp_password->insert(TBp_button);
  161.  
  162.     //    Stay in the input line.
  163.     TDp_password->selectNext(False);
  164.  
  165.     //    Draw the dialog.
  166.     TDp_password->drawView();
  167.  
  168.     //    Execute the dialog.
  169.     TProgram::deskTop->execView(TDp_password);
  170.  
  171.     //    User can't cancel, save what we got as the proper input,
  172.     //    or use the default.
  173.     TPILp_passwordLine->getData(ca_buffer);
  174.  
  175.     //    Done with dialog.
  176.     TObject::destroy(TDp_password);
  177.  
  178.     //    Return input.
  179.     auto char *cp_result = NULL;
  180.     StrAllocCopy(cp_result, ca_buffer);
  181.     return(cp_result);
  182. }
  183.  
  184.  
  185. /*    Prompt both username and password    HTPromptUsernameAndPassword()
  186. **    ---------------------------------
  187. ** On entry,
  188. **    Msg        is the prompting message.
  189. **    *username and
  190. **    *password    are char pointers; they are changed
  191. **            to point to result strings.
  192. **
  193. **            If *username is not NULL, it is taken
  194. **            to point to  a default value.
  195. **            Initial value of *password is
  196. **            completely discarded.
  197. **
  198. ** On exit,
  199. **    *username and *password point to newly allocated
  200. **    strings -- original strings pointed to by them
  201. **    are NOT freed.
  202. **
  203. */
  204. PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *,    Msg,
  205.                           char **,        username,
  206.                           char **,        password)
  207. {
  208.     if (Msg)
  209.     fprintf(stderr, "WWW: %s\n", Msg);
  210.     *username = HTPrompt("Username: ", *username);
  211.     *password = HTPromptPassword("Password: ");
  212. }
  213.  
  214.  
  215. }; // extern "C"